<cfmodule template="../../tag/layout.cfm">
<form method="post" class="form">
  <fieldset>
    <legend>类别基本信息</legend>
    
    <table class="table" width="100%">
      <tbody>
        <tr>
          <th>编号</th>
          <td><input name="id" readonly /></td>
          <th>&nbsp;</th>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <th>类别名称</th>
          <td><input name="text" class="easyui-validatebox" data-options="required:true" /></td>
          <th>类别说明</th>
          <td><input name="description" /></td>
        </tr>
        <tr>
        	<th>类别路径</th>
          	<td><input name="url" /></td>
          	<th>弹出方式</th>
          	<td>
          		<select name="urltarget" class="easyui-combobox" data-options="panelHeight:'auto'">
          			<option value="">请选择弹出方式</option>
          			<option value="_self">当前页面</option>
          			<option value="_blank">弹出页面</option>
          		</select>	
          	</td>
        </tr>
        <tr>
        	<th>是否显示</th>
          	<td><input name="isshow" type="checkbox" value="1" /></td>
          	<th>是否首页</th>
          	<td><input name="isindex" type="checkbox" value="1" /></td>
        </tr>
        <tr>
          <th>是否列表</th>
          <td><input name="islist" type="checkbox" value="1" /></td>
          <th>类别类型</th>
          <td><select id="categorytypeid" name="categorytypeid" readonly="readonly"></select></td>
        </tr>
        <tr>
          <th>类别排序</th>
          <td><input name="seq" class="easyui-validatebox easyui-numberspinner"  data-options="min:0,max:100,required:true" value="0"  style="width:50px;" /></td>
          <th>上级类别</th>
          <td>
          	<select id="categoryid" name="categoryid">
          	</select>
          	<img class="iconImg ext-icon-cross" onclick="$('#categoryid').combotree('clear');" title="清空" />	
          </td>
        </tr>
      </tbody>
    </table>
  </fieldset>
</form>
</cfmodule>
<cfscript>
	if( structKeyExists(rc, "id")  && rc.id > 0 ){
		id = rc.id;
	}else{
		id = 0;
	}
	
	if( structKeyExists(rc, "categorytypeid")  && rc.categorytypeid > 0 ){
		categorytypeid = rc.categorytypeid;
	}else{
		categorytypeid = 0;
	}
</cfscript>
<script type="text/javascript">
	var closeDialog = function($dialog) {
		$dialog.dialog('destroy');
	}
	
	var submitNow = function($dialog, $grid, $pjq, $mainMenu) {
		var url;
		if ($(':input[name="id"]').val().length > 0) {
			url = '?action=category.update'; //更新操作
		} else {
			url = '?action=category.save';	//新增操作
		}

		//alert( $.toJSON( fw.serializeObject($('form')) ));
		$.post(url, fw.serializeObject($('form')), function(result) {
			if (result) {
				$grid.treegrid('reload');
				$mainMenu.tree('reload');
				$dialog.dialog('destroy');
			}
		}, 'json');
	};
	
	var submitForm = function($dialog, $grid, $pjq , $mainMenu) {
		if ($('form').form('validate')) {
			submitNow($dialog, $grid, $pjq , $mainMenu);
		}
	};

	
	$(function(){
		//选择类别类型
		var categorytypeid
		categorytypeid = $('#categorytypeid').combobox({
				required:true,
				editable:false,
				valueField:'id',
				textField:'name',
				url:'?action=category.getCategorytype',
				panelHeight:'auto'
		});
		
		$('#categorytypeid').combobox('setValue',<cfoutput>#categorytypeid#</cfoutput>);
		
		
		//选择父Id
		var categoryid;
		categoryid = $('#categoryid').combotree({
				editable:false,
				idField:'id',
				textField:'text',
				parentField:'pid',
				url:'?action=category.getTree&categorytypeid=<cfoutput>#categorytypeid#</cfoutput>'
		});
		
		//加载数据，初始进度条
		parent.$.messager.progress({
			text : '数据加载中....'
		});

		$.ajax({
		    type: "POST",
		    url: "?action=category.get",
		    data: {
		        id:<cfoutput>#id#</cfoutput>
		    }
		}).done(function(result) {
			$('form').form('load', result); 
			parent.$.messager.progress('close');

		}, 'json');
	})
</script>	 
